/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 16:06:20
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-04-23 17:30:13
 */
import { uploadType } from '@/utils/util'
import { getStore } from '@/utils/store'
import { detailConfig } from '@/views/datacenter/business/elderlyInstitutionsRating/config'
import { cloneDeep } from 'lodash-es'
let userInfo = getStore('userInfo')
// 判断是服务商还是民政
let userType = 'govUser'
if(userInfo.classifyId==5){
	// 服务商
	userType = 'providerUser'
}else if(userInfo.classifyId==3){
	//民政用户
	userType = 'govUser'
}


// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '培训名称', prop: 'trainingName' },
		{ label: '培训单位', prop: 'trainingUnitName' },
		{
			label: '培训类型',
			custome: 'tag',
			prop: 'trainingType',
			code: 'TRAIN_SUPER_TRAIN_TYPE',
		},
		{ label: '参训人员姓名', prop: 'traineesName' },
		{ label: '参训人员身份证信息', prop: 'idCard',plusXing: '2,2' },
		{
			label: '参训人员手机号',
			prop: 'telphone',
			plusXing: '2,2'
		},
		
		{ label: '培训时间', prop: 'trainingTime1' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}
const formConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	column:[
		{
			label:"培训名称",
			prop:"trainingName",
			span:12,
			rules:[
				{required:true,message:"请填写培训名称"}
			]
		},
		{
			label: '培训类型',
			type: 'remoteSelect',
			prop: 'trainingType',
			propName: 'trainingTypeLabel',
			code: 'TRAIN_SUPER_TRAIN_TYPE',
			api: 'getDictItemList',
			span: 12,
			rules:[
				{required:true,message:"请填写培训类型"}
			]
		},
		{
			label:"参训人姓名",
			prop:"traineesName",
			propName:"traineesName",
			type: 'autoSelect',
			api: 'view_dpFoundationPractitioners_page',
			filterKey: 'practitionersName',
			filterLabel: 'practitionersName',
			multiple: false,
			placeholder: '请输入参训人姓名',
			paramsObj: {
				code: 2007
			},
			span:12,
			change:(item, form, value)=>{
				form.idCard=item.idCard
				form.telphone=item.phone
			},
			rules:[
				{required:true,message:"请填写参训人姓名"}
			]
		},
		{
			label:"培训单位",
			prop:"trainingUnitName",
			defaultValue:userInfo.organizationName,
			type:"input",
			disabled:true,
			span:12,
			// rules:[
			// 	{required:true,message:"请填写培训单位"}
			// ]
		},
		{
			label:"培训时间",
			prop:"trainingTime",
			type:"daterange",
			format:"YYYY年MM月DD",
			valueFormat:"YYYY-MM-DD",
			span:12,
			// disabledDate:(date)=>{
			// 	return date.getTime() <= new Date()
			// },
			rules:[
				{required:true,message:"请填写培训时间"}
			]
		},
		{
			label:"参训人员身份证号码",
			prop:"idCard",
			span:12,
			disabled:true,
			// rules:[
			// 	{required:true,message:"请填写参训人员身份证号码"}
			// ]
		},
		{
			label:"参训人员手机号",
			prop:"telphone",
			disabled:true,
			span:12
		},
		{
			label:"培训地点",
			prop:"trainingAddress",
			span:12,
			rules:[
				{required:true,message:"请填写培训地点"}
			]
		},
		{
			label:"授课人",
			prop:"lecturer",
			span:12,
			rules:[
				{required:true,message:"请填写授课人"}
			]
		},
		{
			label:"培训现场照片",
			prop:"trainingPhotos",
			type:"upload",
			span:24
		},
	]
}

export const api = {
	index: 'view_bscTrainingOrg_page',
	add: 'view_bscTrainingOrg_add',
	detail:"view_bscTrainingOrg_view", //打开后编辑的时间范围不显示,需要配置一个钩子operateFormate
	edit: 'view_bscTrainingOrg_edit',
	delete: 'view_bscTrainingOrg_del',
	export:"view_ofsSubsidyApply_grant_export",
	import:"view_bscTrainingOrg_import"
}
export const formateBuilData = (form) => {
	let query = {
		...form,
		buildInfo: undefined,
	}
	if (form.buildInfo && form.buildInfoText) {
		query.checkinBuilding = form.buildInfo[0]
		query.checkinFloor = form.buildInfo[1]
		query.checkinRoom = form.buildInfo[2]
		query.checkinBed = form.buildInfo[3]
	}
	return query
}

export const baseConfig = {
	pageName: '年度总任务管理',
	// 数据字典
	dictcodes: ['TRAIN_SUPER_TRAIN_TYPE'],
	exportMqTopic: '/ning/export/',
	rowKey: 'id',
	tipLabel: 'trainingName',
	addLabel: '添加',
	api: {
		...api,
	},
	auth: {
		...api,
		mulitSet: 'mulitSet',
	},
	// 当前行操作按钮
	menuBtn: [
		{
			label: '详情',
			type: 'primary',
			auth: api.index,
			operate: 'detail',
			text: true,
			show: true,
		},
		{
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: api.edit,
			text: true,
			show: true,
		},
		{
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: api.delete,
			text: true,
			show: true,
		},
	],
	formConfig,
	detailConfig:formConfig,
	dialogConfig: {
		width: '80%',
	},
	// 搜索
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{ label: '培训名称', prop: 'trainingName', type: 'input', span: 8 },
			{ label:"参训人姓名",prop:"traineesName", type: 'input', span: 8 },
			{ label:"身份证号",prop:"idCard", type: 'input', span: 8 },
			{
				label: '培训类型',
				type: 'remoteSelect',
				prop: 'trainingType',
				propName: 'trainingTypeLabel',
				code: 'TRAIN_SUPER_TRAIN_TYPE',
				api: 'getDictItemList',
				span: 8,
			},
			{
				label: '联系方式',
				prop: 'telphone',
				span: 8,
			},
			{
				label: '培训时间开始',
				prop: 'trainingStartTimeBetween',
				type: 'daterange',
				format:"YYYY年MM月DD",
				valueFormat:"YYYY-MM-DD",
				span: 8,
			},
			{
				label: '培训结束开始',
				prop: 'trainingEndTimeBetween',
				type: 'daterange',
				format:"YYYY年MM月DD",
				valueFormat:"YYYY-MM-DD",
				span: 8,
			},
		],
	},
	// 列表
	tableConfig,
	importConfig: {
		tabSteps: [
			{
				label: '下载模板',
				download: '下载模板',
				active: 1,
				rules: [
					{
						label: '下载最新导入模板。共2个：',
						children: [
							{
								label: '《机构内训信息表》',
								link: true,
								url: 'view_bscTrainingOrg_downloadTemplate',
							},
						],
					},
				],
			},
			{
				label: '导入《机构内训信息表》',
				description: '',
				uploadTip: '机构内训信息表',
				active: 2,
				url: 'view_bscTrainingOrg_import',
				code: 4005,
				rules: [
					{
						label: '导入规则说明:',
						children: [
							{
								label: '(1)导入模式为“覆盖导入”，待导入的机构内训信息表会覆盖平台已存在的',
							},
						],
					},
				],
			},
		],
	},
	saveFormate: async (form) => {
		console.log('sahng',form)
		let copyForm = JSON.parse(JSON.stringify(form))
		if(copyForm.trainingTime){
			copyForm.trainingStartTime = copyForm.trainingTime[0]
			copyForm.trainingEndTime = copyForm.trainingTime[1]
			copyForm.trainingTime = undefined
		}
		copyForm.trainingUnitName = userInfo.organizationName
		copyForm.unitCreditCode = userInfo.organizationId
		return new Promise((resolve, reject) => {
			resolve(copyForm)
		})
	},
	operateFormate: async (form, type) => {
		let copyForm = JSON.parse(JSON.stringify(form))
		if(copyForm.trainingStartTime&&copyForm.trainingEndTime){
			copyForm.trainingTime = [copyForm.trainingStartTime,copyForm.trainingEndTime]
			copyForm.trainingTime1 = copyForm.trainingStartTime+'~'+copyForm.trainingEndTime
		}
		return Promise.resolve(copyForm)
	},
	onLoadFormate: async (arr) => {
		let tableData = arr.map((item) => {
			if(item.trainingStartTime&&item.trainingEndTime){
				item.trainingTime = [item.trainingStartTime,item.trainingEndTime]
				item.trainingTime1 = item.trainingStartTime+'~'+item.trainingEndTime
			}
			return item
		})
		return Promise.resolve(tableData)
	},
	beforeOnLoadFormate(form) {
		let copyForm = cloneDeep(form)
		if(copyForm.trainingStartTimeBetween){
			copyForm.trainingStartTimeBetween=copyForm.trainingStartTimeBetween.join(',')
		}
		if(copyForm.trainingEndTimeBetween){
			copyForm.trainingEndTimeBetween = copyForm.trainingEndTimeBetween.join(',')
		}
		// 处理搜索条件
		if(copyForm.trainingTime){
			copyForm.trainingStartTime = copyForm.trainingTime[0]
			copyForm.trainingEndTime = copyForm.trainingTime[1]
			copyForm.trainingTime = undefined
		}
		return new Promise((resolve, reject) => {
			resolve(copyForm)
		})
	},
}
